﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MemberLogin : System.Web.UI.Page
{
    MODEL.BaseInfo MBI = new MODEL.BaseInfo();
    MODEL.BaseInfo _MBI = new MODEL.BaseInfo();

    BLL.BaseInfo BBI = new BLL.BaseInfo();


    #region 封装字段
    private string keywords;
    private string description;

    public string Keywords
    {
        get { return keywords; }
        set { keywords = value; }
    }
    public string Description
    {
        get { return description; }
        set { description = value; }
    }
    #endregion


    protected void Page_Load(object sender, EventArgs e)
    {
       
        if(!Page.IsPostBack)
        {
         BaseInfoInit();
            if(Session["UserInfo"]!=null)
            {
                Response.Redirect("Welcome1.aspx");
            }
        }
        
    }


    #region BaseInfoInit
    protected void BaseInfoInit()
    {
        try
        {

            MBI.BI_ID = 1;

            _MBI = BBI.GetDataByID(MBI);

            Page.Title = _MBI.BI_Content;


            MBI.BI_ID = 2;

            _MBI = BBI.GetDataByID(MBI);

            this.Keywords = "<meta http-equiv=\"keywords\" content=\"" + _MBI.BI_Content + "\" />";


            MBI.BI_ID = 3;

            _MBI = BBI.GetDataByID(MBI);

            this.Description = "<meta http-equiv=\"description\" content=\"" + _MBI.BI_Content + "\" />";


            head1.DataBind();
        }
        catch (Exception)
        {

        }
    }
    #endregion


    protected void Button1_Click(object sender, ImageClickEventArgs e)
    {
        if (Session["Validatacode"].ToString().Equals(txtValid.Text.Trim()))
        {
            SQLExpressDAL.UsersTableAdapters.UsersTableAdapter userAdp= new SQLExpressDAL.UsersTableAdapters.UsersTableAdapter();
            SQLExpressDAL.Users.UsersDataTable tab=userAdp.UserLoginCheck(this.txtName.Text.Trim(), this.txtPwd.Text.Trim());

            SQLExpressDAL.DealRuleTableAdapters.WebSiteConfigTableAdapter configAdp = new SQLExpressDAL.DealRuleTableAdapters.WebSiteConfigTableAdapter();
            SQLExpressDAL.DealRule.WebSiteConfigDataTable configTab = configAdp.GetData();

           if (tab.Rows.Count > 0)
           {
               Session["UserInfo"] = tab;
               Session["UserID"] = tab.Rows[0]["UserID"];
               Session["WebSiteConfig"] = configTab;
               Response.Redirect("welcome1.aspx");
           }
           else
           {
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('帐号有误或者密码错误')", true);
           }
        }
        else
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg","alert('验证码错误')",true);
        }
    }
}
